<template>
    <view class="audit-container">
        <!-- 审核信息卡片 -->
        <view class="info-card">
            <view class="info-item">
                <text class="label">申请用户</text>
                <text class="value">{{cashInfo.user_info}}</text>
            </view>
            <view class="info-item">
                <text class="label">提现金额</text>
                <text class="value highlight">￥{{cashInfo.cash_amount}}</text>
            </view>
            <view class="info-item">
                <text class="label">申请时间</text>
                <text class="value">{{cashInfo.apply_at}}</text>
            </view>
            <view class="info-item">
                <text class="label">提现状态</text>
                <text class="value status" :class="getStatusClass">{{cashInfo.cash_status_string}}</text>
            </view>
            <view class="info-item">
                <text class="label">提现方式</text>
                <text class="value">{{cashInfo.cash_way_string}}</text>
            </view>
            <view class="info-item">
                <text class="label">账号余额</text>
                <text class="value">￥{{cashInfo.pay_account_info}}</text>
            </view>
        </view>

        <!-- 充值金额输入 -->
        <view class="form-section">
            <view class="form-title">支付账号充值金额</view>
            <view class="input-box">
                <text class="prefix">￥</text>
                <input 
                    type="digit"
                    v-model="rechargeAmount"
                    placeholder="请输入充值金额（选填）"
                    class="amount-input"
                />
            </view>
        </view>

        <!-- 操作按钮 -->
        <view class="btn-section">
            <view 
                class="submit-btn" 
                :class="{'disabled': cashInfo.cash_status !== 1}"
                @click="handlePass"
            >同意提现</view>
        </view>
    </view>
</template>

<script>
import request from '@/utils/request'

export default {
    data() {
        return {
            id: '', // 提现记录ID
            cashInfo: {
                user_info: '',
                cash_amount: '',
                apply_at: '',
                cash_status: '',
                cash_status_string: '',
                cash_way_string: '',
                pay_account_info: ''
            },
            rechargeAmount: '' // 充值金额
        }
    },
    onLoad(options) {
        if (!options.id) {
            uni.showModal({
                title: '错误提示',
                content: '缺少必要的参数',
                showCancel: false,
            })
            return
        }
        this.id = options.id
        this.getCashInfo()
    },
    methods: {
        // 获取提现详情
        async getCashInfo() {
            if (!this.id) return
            
            try {
                const res = await request({
                    url: '/wechat/admin/cashInfo',
                    data: { id: this.id }
                })
                
                if (res.code === 0 && res.data) {
                    this.cashInfo = res.data.cashInfo
                    // 如果没有返回数据，说明记录不存在
                    if (!this.cashInfo) {
                        uni.showModal({
                            title: '错误提示',
                            content: '提现记录不存在',
                            showCancel: false,
                        })
                    } else if (this.cashInfo.cash_status !== 1) {
                        uni.showModal({
                            title: '错误提示',
                            content: '当前提现状态为：' + this.cashInfo.cash_status_string,
                            showCancel: false,
                        })
                    }
                } else {
                    uni.showModal({
                        title: '错误提示',
                        content: res.message || '获取提现详情失败',
                        showCancel: false,
                    })
                }
            } catch (err) {
                console.error('获取提现详情失败', err)
                uni.showToast({
                    title: '加载失败',
                    icon: 'none'
                })
            }
        },
        
        // 处理同意提现
        async handlePass() {
            if (this.cashInfo.cash_status !== 1) {
                uni.showToast({
                    title: '当前状态不可审核',
                    icon: 'none'
                })
                return
            }
            
            try {
                uni.showLoading({
                    title: '处理中...'
                })
                
                const data = {
                    id: this.id
                }
                
                // 如果有填写充值金额，添加到请求参数
                data.amount = this.rechargeAmount ? this.rechargeAmount : null

                const res = await request({
                    url: '/wechat/admin/cashPass',
                    data
                })

                if (res.code === 0) {
                    uni.showToast({
                        title: '审核成功',
                        icon: 'success'
                    })

                    // 刷新当前页面
                    uni.reLaunch({
                        url: this.$route.fullPath
                    })
                } else {
                    uni.showToast({
                        title: res.message || '审核失败',
                        icon: 'none'
                    })
                }
            } catch (err) {
                console.error('审核失败', err)
                uni.showToast({
                    title: '审核失败',
                    icon: 'none'
                })
            } finally {
                uni.hideLoading()
            }
        }
    },
    computed: {
        getStatusClass() {
            const statusMap = {
                1: 'status-waiting',  // 待审核 - 橙色
                2: 'status-success',  // 提现中 - 绿色
                3: 'status-finish',   // 成功 - 蓝色
                4: 'status-fail',     // 驳回 - 红色
                9: 'status-fail'      // 失败 - 红色
            }
            return statusMap[this.cashInfo.cash_status] || 'status-default'
        }
    }
}
</script>

<style>
.audit-container {
    min-height: 100vh;
    background-color: #f8f9fc;
    padding: 30rpx;
}

.info-card {
    background-color: #ffffff;
    border-radius: 24rpx;
    padding: 30rpx;
    margin-bottom: 30rpx;
    box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
}

.info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20rpx 0;
    border-bottom: 2rpx solid #f0f2f7;
}

.info-item:last-child {
    border-bottom: none;
}

.label {
    font-size: 28rpx;
    color: #666666;
}

.value {
    font-size: 28rpx;
    color: #333333;
}

.value.highlight {
    color: #ff4d4f;
    font-weight: bold;
    font-size: 32rpx;
}

.value.status {
    font-weight: 500;
}

/* 状态颜色 */
.status-waiting {
    color: #ff9900;  /* 橙色 - 待审核 */
}

.status-success {
    color: #07c160;  /* 绿色 - 已通过 */
}

.status-fail {
    color: #ff4d4f;  /* 红色 - 已拒绝 */
}

.status-finish {
    color: #2b85ff;  /* 蓝色 - 已完成 */
}

.status-default {
    color: #999999;  /* 灰色 - 其他状态 */
}

.form-section {
    background-color: #ffffff;
    border-radius: 24rpx;
    padding: 30rpx;
    margin-bottom: 60rpx;
    box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
}

.form-title {
    font-size: 28rpx;
    color: #333333;
    font-weight: 500;
    margin-bottom: 20rpx;
}

.input-box {
    display: flex;
    align-items: center;
    background-color: #f8f9fc;
    border-radius: 12rpx;
    padding: 20rpx;
}

.prefix {
    font-size: 32rpx;
    color: #333333;
    margin-right: 10rpx;
}

.amount-input {
    flex: 1;
    font-size: 32rpx;
    color: #333333;
}

.btn-section {
    padding: 0 30rpx;
}

.submit-btn {
    background: linear-gradient(135deg, #2b85ff, #3a90ff);
    height: 88rpx;
    line-height: 88rpx;
    text-align: center;
    color: #ffffff;
    font-size: 32rpx;
    font-weight: 500;
    border-radius: 44rpx;
    box-shadow: 0 8rpx 16rpx rgba(43, 133, 255, 0.2);
    transition: all 0.3s;
}

.submit-btn:active {
    transform: scale(0.98);
    box-shadow: 0 4rpx 8rpx rgba(43, 133, 255, 0.2);
}

.submit-btn.disabled {
    background: #ccc;
    cursor: not-allowed;
}
</style> 